package com.dfbz.demo01;

import java.io.File;
import java.io.FileFilter;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo07_FileFilter递归获取指定文件 {
    public static void main(String[] args) {

        File file = new File("E:\\BaiduNetDiskWorkspace\\workspace_class");

        searchFile(file);

    }

    public static void searchFile(File file) {

        // 只要这个目录的子目录和java文件
        File[] files = file.listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return pathname.getName().endsWith(".java") || pathname.isDirectory();
            }
        });


        for (File tempFile : files) {
            if (tempFile.isDirectory()) {
                searchFile(tempFile);
            } else {
                System.out.println(tempFile.getName());
            }
        }
    }


}
